package org.test.boot.rocketmq.producer;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.test.boot.rocketmq.config.MqProperties;

import javax.annotation.Resource;

@Component
public class SimpleDemoProducer implements CommandLineRunner {

    private static final Logger LOGGER = LoggerFactory.getLogger(SimpleDemoProducer.class);

    @Resource
    private MqProperties mqProperties;

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void run(String... args) throws Exception {
        SendResult sendResult = rocketMQTemplate.syncSend(mqProperties.getTopic(), "Hello, World!");
        LOGGER.info("send result: " + sendResult);
    }
}
